package cn.edu.ctbu.firsthello.controller;

import cn.edu.ctbu.firsthello.domain.Student;
import cn.edu.ctbu.firsthello.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

@Controller
@Slf4j
public class StudentController {

@Autowired
    StudentService studentService;


    @RequestMapping("/student/list")
    public String list(Model model,String name){
        log.info("姓名:{}",name);
        List<Student> all = new ArrayList<>();
        if(name==null ||name.equals("")){
             all = studentService.findAll();
        }else{
            all = studentService.findByNameLike("%"+name+"%");

        }

        model.addAttribute("data",all);

        return "/student/data";

    }
}
